import os
import time
from time import sleep

#连接adb 192.168.137.236:5555
def adb_connect1(IP):
    os.system(f"adb connect {IP}")
    
#adb_shell终端指令输入
def adb_cmd(cmd):
    output_date = os.popen(f"adb shell {cmd}")
    print(output_date.read())

#获取屏幕物理尺寸
def phoneSize(x, y):
    adb_cmd(f'wm size')

#模拟鼠标的点击事件，x，y为点击的坐标
def touch(x, y):
    adb_cmd(f'input tap {x} {y}')

#模拟文字输入事件，text输入字符串
def text(text):
    adb_cmd(f'input text {text}')

#模拟滑动事件，x1,y1为起始坐标,x2,y2为终点坐标，t为滑动的时间
def swipe_num(x1,y1,x2,y2,t,delay_t):
    while(1):
        #t = 1000*t
        adb_cmd(f'input touchscreen swipe {x1} {y1} {x2} {y2} {t}')
        sleep(delay_t)
        
#模拟按键事件，3代表回主页按键，4代表返回按键
def keyevent(x):
    adb_cmd(f'input keyevent {x}')

#模拟拖动事件，x1,y1为起始坐标,x2,y2为终点坐标，t为拖动的时间
def draganddrop(x1,y1,x2,y2,t):
    adb_cmd(f'input draganddrop {x1} {y1} {x2} {y2} {t}')

def screen():
    print("scap")
    adb_cmd(f'screencap -p /sdcard/01.png')
    print("1")
    sleep(0.1)
    os.popen(f"pull /sdcard/01.png ../")
    #adb_cmd(f'pull /sdcard/01.png ../')#反斜杠要转
    
def advert(x1,y1,x2,y2):
    while(1):
        touch(x1,y1)
        sleep(1)
        touch(x2,y2)
        sleep(35)

    
if __name__ == "__main__":
	#adb_connect1(IP).
    #touch(x, y)
    #text(text)
    swipe_num(540,2000, 540, 1000, 100, 10)
    #screen()
    #keyevent(x)
    #draganddrop(x1,y1,x2,y2,t)
    #advert(995,144,523,1573)# 百度极速广告
    #advert(995,144,523,1416)# 百度极速翻卡

